package com.auto.survey.activity.monitoring.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.auto.survey.R
import com.auto.survey.activity.monitoring.entity.MonitoringPoint

class CtrlSttingAdapter : RecyclerView.Adapter<CtrlSttingAdapter.CtrlSttingsViewHodler>(){
    private var mItems = mutableListOf<MonitoringPoint>()

    fun setItems(items: List<MonitoringPoint>) {
        mItems.clear()
        mItems.addAll(items)
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CtrlSttingsViewHodler {

        val view = LayoutInflater.from(parent.context).inflate(R.layout.adapter_ctrl_settings, parent, false)
        return CtrlSttingsViewHodler(view)
    }

    override fun onBindViewHolder(holder: CtrlSttingsViewHodler, position: Int) {
        holder.pname.text = "${mItems[position].pointName}:"
    }

    override fun getItemCount(): Int {
        if (mItems.isNotEmpty()) {
            return mItems.size
        }
        return 0
    }


    inner class CtrlSttingsViewHodler(itemview: View) : RecyclerView.ViewHolder(itemview){
        val pname = itemview.findViewById<TextView>(R.id.tv_ctrlsetting_item_pname)
        val pheight = itemview.findViewById<EditText>(R.id.edit_ctrlsetting_item_height)
        val pnumber = itemview.findViewById<EditText>(R.id.edit_ctrlsetting_item_mirrornum)
    }
}